﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports System.Data.Common

Public Class System_Defaults
#Region "Constants"
    Protected Const _cFName As String = "Field_Name"
    Protected Const _cFValue As String = "Field_Key"
    Protected Const _cType As String = "Field_Type"
    Protected Const _cDesc As String = "Field_Description"
    Protected Const _cModifiedDate As String = "ModifiedDate"
#End Region
#Region "Private"
    Private Shared _fieldName As String = String.Empty
    Private Shared _fieldValue As String = String.Empty
    Private Shared _fieldType As String = String.Empty
    Private Shared _description As String = String.Empty
    Private Shared _modifiedDate As Date

    Private Shared _blExist As Boolean = False
    Private Shared el As New errorLog
#End Region
#Region "Public"
    Public Property FieldName() As String
        Get
            Return _fieldName
        End Get
        Set(ByVal value As String)
            _fieldName = value
        End Set
    End Property
    Public Property FieldValue() As String
        Get
            Return _fieldValue
        End Get
        Set(ByVal value As String)
            _fieldValue = value
        End Set
    End Property
    Public Property FieldType() As String
        Get
            Return _fieldType
        End Get
        Set(ByVal value As String)
            _fieldType = value
        End Set
    End Property
    Public Property Description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property
    Public Property ModifiedDate() As Date
        Get
            Return _modifiedDate
        End Get
        Set(ByVal value As Date)
            _modifiedDate = value
        End Set
    End Property
#End Region
    Public Function GetSystemDefault(ByVal FieldName As String) As Boolean
        _fieldName = FieldName

        Dim db As Database = DbStoreFactory.CreateDatabase
        Dim cmd As DbCommand
        Dim reader As IDataReader = Nothing

        If Not (_fieldName = String.Empty) Then
            cmd = db.GetStoredProcCommand("System_GetSystemDefaults")
            db.DiscoverParameters(cmd)
            cmd.Parameters("@eFieldName").Value = _fieldName

            reader = db.ExecuteReader(cmd)

            Do While (reader.Read)
                _fieldValue = reader(_cFValue).ToString
                _description = reader(_cDesc).ToString
                _fieldType = reader(_cType).ToString
                _modifiedDate = Convert.ToDateTime(reader(_cModifiedDate).ToString)

                _blExist = True
            Loop

        End If

        Return _blExist
    End Function
End Class
